package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.UserDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.User;
import edu.ynu.se.xiecheng.achitectureclass.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController extends LogicController<UserService, UserDao, User, Long> {

    public UserController(@Autowired UserService service) {
        super(service);
    }

    @PostMapping
    public Boolean register(@RequestBody User entity) {
        return super.POST(entity) != null;
    }

    @PostMapping("/login")
    public Boolean login(@RequestBody Map<String, String> params) {
        System.out.println(params);
        String userName = params.get("userName");
        String password = params.get("password");
        return super.getService().loginUser(userName, password);
    }
}
